import axios from 'axios'
// import router from 'router'

export default function ({ isServer, req, redirect, route }) {
  let pc='https://localhost:3000/';
  let yd ='https://localhost:3000/Mobile';
  let isMobile = (ua) => {
    return !!ua.match(/AppleWebKit.*Mobile.*/)
  }
  // console.log(route.fullPath);
  let a = route.fullPath;
  let userAgent = req ? req.headers['user-agent'] : navigator.userAgent || ''
  if(isMobile(userAgent)){

    if(route.fullPath == '/'){
      redirect('/Mobile');
    }else if(route.fullPath == '/Business'){
      redirect('/Mobile/Business');
    }else if(route.fullPath == '/Finance'){
      redirect('/Mobile/Finance');
    }else if(route.fullPath == '/About'){
      redirect('/Mobile/About');
    }else if(route.fullPath == '/Personnel'){
      redirect('/Mobile/Personnel');
    }else if(route.fullPath == '/KnowLedge'){
      redirect('/Mobile/KnowLedge');
    }else if(route.fullPath.slice(0,5) == '/Info'){
      redirect('/Mobile'+'/Info');
    }else if(route.fullPath.slice(0,8) == '/Details'){
      redirect('/Mobile');
    }
    else if(route.fullPath.slice(0,15) == '/ServiceDetails'){
      redirect('/Mobile');
    }else if(route.fullPath == '/Qualifications'){
      redirect('/Mobile');
    }
    else if(route.fullPath == '/Mall'){
      redirect('/Mobile');
    }
    else if(route.fullPath == '/PersonalCenter'){
      redirect('/Mobile');
    }
    else if(route.fullPath == '/Login'){
      redirect('/Mobile');
    }
    else if(route.fullPath == '/Architect'){
      redirect('/Mobile');

    }
    // console.log(a);
  }else{
    if(route.fullPath == '/Mobile'){
      redirect('/');
    }else if(route.fullPath == '/Mobile/Business'){
      redirect('/Business');
    }else if(route.fullPath == '/Mobile/Finance'){
      redirect('/Finance');
    }else if(route.fullPath == '/Mobile/About'){
      redirect('/About');
    }else if(route.fullPath == '/Mobile/Personnel'){
      redirect('/Personnel');
    }else if(route.fullPath == '/Mobile/KnowLedge'){
      redirect('/KnowLedge');
    }else if(route.fullPath.slice(0,12) == '/Mobile/Info'){
      redirect('/Info');
    }else if(route.fullPath.slice(0,15) == '/Mobile/Details'){
      redirect(route.fullPath.slice(7));
    }

  }
  // return isMobile(userAgent) ? redirect(route.fullPath) : redirect(route.fullPath);
  // 使用redirect 重定向到外链需要加上前缀:https / https
}
